package com.itheima.edu.info.manager.controller;

import com.itheima.edu.info.manager.domain.Teacher;
import com.itheima.edu.info.manager.service.TeacherService;
import org.jetbrains.annotations.NotNull;

import java.util.Scanner;

public class TeacherController {
    Scanner sc = new Scanner(System.in);
    TeacherService teacherService = new TeacherService();
    String id;
    public void teacherInfo() {
        t:
        while (true) {
            System.out.println("--------欢迎来到 <老师> 管理系统--------");
            System.out.println("请输入您的选择: 1.添加老师  2.删除老师  3.修改老师  4.查看老师  5.退出");
            int a = sc.nextInt();
            switch (a) {
                case 1:
                    addTeacher();
                    break;
                case 2:
                    System.out.println("删除");
                    break;
                case 3:
                    System.out.println("修改");
                    break;
                case 4:
                    System.out.println("查看");
                    break;
                case 5:
                    System.out.println("感谢使用老师管理系统，再见");
                    break t;
                default:
                    System.out.println("您的输入有误，请重新输入！！！");
                    break;
            }
        }
    }

    private void addTeacher() {
        System.out.println("请输入老师的编号:");
        while (true) {
            id = sc.next();
            if (!teacherService.isEmptyById(id)) {
                System.out.println("您输入的老师编号已存在，请重新输入:");
            }else {
                break;
            }
        }
        if (teacherService.addTeacher(input(id))){
            System.out.println("添加成功");
        }else {
            System.out.println("添加失败");
        }
    }

    private Teacher input(String id){
        System.out.println("请输入老师姓名:");
        String name = sc.next();
        System.out.println("请输入老师年龄:");
        int age = sc.nextInt();
        System.out.println("请输入老师生日:");
        String birth = sc.next();
        Teacher teacher=new Teacher();
        teacher.setId(id);
        teacher.setName(name);
        teacher.setAge(age);
        teacher.setBirthday(birth);
        return teacher;
    }
}
